//
//  Thread+QueueBlock.m
//  YanXiuWang
//
//  Created by 慧趣小歪 on 16/11/16.
//  Copyright © 2016年 小分队. All rights reserved.
//

#import "Thread+QueueBlock.h"

void thread_safe_main(_Nonnull dispatch_block_t queueBlock) {
    if ([NSThread isMainThread]) {
        queueBlock();
    } else {
        dispatch_async(dispatch_get_main_queue(), queueBlock);
    }
}

void thread_main(_Nonnull dispatch_block_t queueBlock) {
    dispatch_async(dispatch_get_main_queue(), queueBlock);
}
void thread_global(_Nonnull dispatch_block_t queueBlock) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), queueBlock);
}
void thread_global_high(_Nonnull dispatch_block_t queueBlock) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), queueBlock);
}
void thread_global_low(_Nonnull dispatch_block_t queueBlock) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), queueBlock);
}
void thread_background(_Nonnull dispatch_block_t queueBlock) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), queueBlock);
}

void thread_main_after(NSTimeInterval delayInSeconds, _Nonnull dispatch_block_t queueBlock) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), queueBlock);
}
void thread_global_after(NSTimeInterval delayInSeconds, _Nonnull dispatch_block_t queueBlock) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), queueBlock);
}
